<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container{
            width: 400px;
            height: auto;
            overflow: hidden;
            padding:10px;
            border:solid 1px #ddd;
            display:inline-block;
        }
        video{
            width:100%;
        }
    </style>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        
        class Video extends React.Component{
            // 声明 state 属性
            state = {
                src: 'https://www.kuaidoushe.com/video.php'
            }

            //1. 构造方法
            constructor(){
                console.log('constructor 构造方法执行')
                super();
            }

            //2. 组件将要挂载 
            componentWillMount(){
                console.log('componentWillMount 组件将要挂载');
            }

            //3. 渲染方法
            render(){
                console.log('render 组件渲染中....')
                return <div className="container" onClick={this.change}>
                        <video src={this.state.src} controls autoPlay></video>                    
                    </div>
            }

            //4. 挂载(渲染)完成
            componentDidMount(){
                console.log('componentDidMount 组件挂载完成....');
            }


            componentWillUnmount(){
                console.log('componentWillUnmount 组件将要卸载');
            }

            change = (e) => {
                this.setState({
                    src: 'https://www.kuaidoushe.com/video.php?t='+Date.now()
                })
            }

        }



        //获取网页中 button
        let btns = document.querySelectorAll('button');

        btns[0].onclick = function(){
            ReactDOM.render(<Video />, document.querySelector("#root"))
        }

        btns[1].onclick = function(){
            ReactDOM.unmountComponentAtNode(document.querySelector('#root'));
        }


    </script>


</body>
</html>